package com.ikas.ai.server.module.steady.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ikas.ai.server.module.steady.model.dto.SteadyAlarmCacheDTO;
import com.ikas.ai.server.module.steady.model.dto.StyAlarmDataPageDto;
import com.ikas.ai.server.module.steady.model.dto.StyAlarmDataQueryDto;
import com.ikas.ai.server.module.steady.model.po.SteadyAlarmData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Timestamp;
import java.util.List;

/**
 * <p>
 * 稳态预警数据表 Mapper 接口
 * </p>
 *
 * @author wuyf
 * @since 2023-12-13
 */
public interface SteadyAlarmDataMapper extends BaseMapper<SteadyAlarmData> {

    List<SteadyAlarmCacheDTO> selectCountBySolved(@Param("solved") Integer solved);

    Integer selectCountBySolvedAndMachineNo(@Param("solved") Integer solved, @Param("machineNo") String machineNo, @Param("steadyType") Integer steadyType);

    List<StyAlarmDataPageDto> list(StyAlarmDataQueryDto queryDto);

    @Delete("delete from t_steady_alarm_data where alarm_time between #{startTime} and #{endTime} and monitor_mete_id = #{meteId}")
    void deleteAlarmData(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("meteId") Long meteId);

    @Select({
            "<script>",
            "select count(*) from t_steady_alarm_data",
            "where monitor_mete_id in",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    int selectCountByMonitorMete(@Param("ids") List<Long> ids);
}
